package com.example.Sao.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.Sao.R;

import java.util.ArrayList;

/**
 * @ProjectName: scan
 * @Package: com.example.MyApplication.Adapter
 * @ClassName: HistoryAdaptero
 * @Description: java类作用描述
 * @Author: 作者名
 * @CreateDate: 2020/4/21 21:58
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/4/21 21:58
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class HistoryAdaptero extends RecyclerView.Adapter<HistoryAdaptero.MViewHolder> {
    private HistoryCallBack historyCallBack;
    private boolean isExplore;
    private Context mContext;
    private ArrayList<String> history_list;

    public HistoryAdaptero(Context mContext,ArrayList<String>history_list,boolean isExplore,HistoryCallBack historyCallBack){
        this.historyCallBack = historyCallBack;
        this.isExplore = isExplore;
        this.mContext = mContext;
        this.history_list = history_list;
    }

    @Override
    public int getItemCount() {
        if (history_list==null){
            return 0;
        }else {
            return history_list.size();
        }
    }

    @NonNull
    @Override
    public HistoryAdaptero.MViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v = View.inflate(mContext, R.layout.adpter_history,null);
        return new HistoryAdaptero.MViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull HistoryAdaptero.MViewHolder mViewHolder, int i) {
        final String word = history_list.get(i);
        mViewHolder.textView.setText(word);
        mViewHolder.te.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (historyCallBack!=null){
                    historyCallBack.historycallback(word);
                }
            }
        });
    }

    class MViewHolder extends RecyclerView.ViewHolder{
        RelativeLayout te;
        TextView textView;
        public MViewHolder(View v){
            super(v);
            textView = v.findViewById(R.id.text4);
            te = v.findViewById(R.id.history33);
        }
    }
}
